﻿using NLog;

namespace Frame.Core.Common.Common
{
    public class NlogHelper
    {
        readonly static Logger sqlServerLogger = LogManager.GetLogger("SqlServerLog");//记录到数据库
        readonly static Logger serviceLogger = LogManager.GetLogger("IInterceptorAOPLog");//记录到文件
        /// <summary>
        /// 
        /// </summary>
        /// <param name="logLevel">级别</param>
        /// <param name="ip">ip地址</param>
        /// <param name="userName">用户名</param>
        /// <param name="msg">信息</param>
        /// <param name="actionName">action名称</param>
        /// <param name="eventType">事件类型</param>
        public static void SqlServerLog(LogLevel logLevel, string ip, string userName,string msg, string actionName,string eventType)
        {
            LogEventInfo theEvent = new LogEventInfo(logLevel, actionName, msg);
            theEvent.Properties["IP"] = ip;
            theEvent.Properties["UserName"] = userName;
            theEvent.Properties["ActionName"] = actionName;
            theEvent.Properties["EventType"] = eventType;
            theEvent.Properties["LogLevel"] = logLevel.ToString();
            sqlServerLogger.Log(theEvent);
        }

        public static void ServiceLog(string content)
        {
            LogEventInfo theEvent = new LogEventInfo(LogLevel.Trace, "", content);
            serviceLogger.Log(theEvent);
        }


        public static void Flush()
        {
            LogManager.Flush();
        }
    }
}
